import request from '@/utils/request'
import type {
  IAttrInfoData,
  IAddItemCateGoryData,
  IAddItemCateGoryRequestData,
  IDetailItemCateGoryData,
} from './type'

enum API {
  GET_CATEGORY1_LIST = '/admin/product/getCategory1',
  GET_CATEGORY2_LIST = '/admin/product/getCategory2/',
  GET_CATEGORY3_LIST = '/admin/product/getCategory3/',
  ADD_CATEGORY1 = '/admin/product/saveCategory1',
  ADD_CATEGORY2 = '/admin/product/saveCategory2',
  ADD_CATEGORY3 = '/admin/product/saveCategory3',
  UPDATE_CATEGORY1 = '/admin/product/updateeCategory1',
  UPDATE_CATEGORY2 = '/admin/product/updateeCategory2',
  UPDATE_CATEGORY3 = '/admin/product/updateeCategory3',
  DELETE_CATEGORY1 = '/admin/product/removeCategory1/',
  DELETE_CATEGORY2 = '/admin/product/removeCategory2/',
  DELETE_CATEGORY3 = '/admin/product/removeCategory3/',
  DETAIL_CATEGORY1 = '/admin/product/get/category1/',
  DETAIL_CATEGORY2 = '/admin/product/get/category2/',
  DETAIL_CATEGORY3 = '/admin/product/get/category3/',
}

// 获取一级分类列表
export const getCateGory1 = () => {
  return request.get<any, IAttrInfoData>(API.GET_CATEGORY1_LIST)
}

// 新增一级分类
export const addCategory1 = (data: IAddItemCateGoryRequestData) => {
  return request.post<any, IAddItemCateGoryData>(API.ADD_CATEGORY1, data)
}

// 修改一级分类
export const updateCategory1 = (data: IAddItemCateGoryRequestData) => {
  return request.put<any, any>(API.UPDATE_CATEGORY1, data)
}

// 删除一级分类
export const deleteCategory1 = (id: number) => {
  return request.delete<any, IAddItemCateGoryData>(API.DELETE_CATEGORY1 + id)
}

// 一级分类详情
export const detailCategory1 = (id: number) => {
  return request.get<any, IDetailItemCateGoryData>(API.DETAIL_CATEGORY1 + id)
}

// 获取二级分类列表
export const getCateGory2 = (id: number) => {
  return request.get<any, IAttrInfoData>(API.GET_CATEGORY2_LIST + id)
}

// 新增二级分类
export const addCategory2 = (data: IAddItemCateGoryRequestData) => {
  return request.post<any, IAddItemCateGoryData>(API.ADD_CATEGORY2, data)
}

// 修改一级分类
export const updateCategory2 = (data: IAddItemCateGoryRequestData) => {
  return request.put<any, any>(API.UPDATE_CATEGORY2, data)
}

// 删除二级分类
export const deleteCategory2 = (id: number) => {
  return request.delete<any, IAddItemCateGoryData>(API.DELETE_CATEGORY2 + id)
}

// 二级分类详情
export const detailCategory2 = (id: number) => {
  return request.get<any, IDetailItemCateGoryData>(API.DETAIL_CATEGORY2 + id)
}

// 三级
// 获取二级分类列表
export const getCateGory3 = (id: number) => {
  return request.get<any, IAttrInfoData>(API.GET_CATEGORY3_LIST + id)
}

// 新增二级分类
export const addCategory3 = (data: IAddItemCateGoryRequestData) => {
  return request.post<any, IAddItemCateGoryData>(API.ADD_CATEGORY3, data)
}

// 修改一级分类
export const updateCategory3 = (data: IAddItemCateGoryRequestData) => {
  return request.put<any, any>(API.UPDATE_CATEGORY3, data)
}

// 删除二级分类
export const deleteCategory3 = (id: number) => {
  return request.delete<any, IAddItemCateGoryData>(API.DELETE_CATEGORY3 + id)
}

// 二级分类详情
export const detailCategory3 = (id: number) => {
  return request.get<any, IDetailItemCateGoryData>(API.DETAIL_CATEGORY3 + id)
}
